<template>
  <div class="Word">
    <span style="color: red">操作说明：</span
    >点“加盖印章”按钮即可，插入印章时的用户名为：李志，密码默认为：111111。
    <div style="height: 800px; width: auto" v-html="poHtmlCode" />
  </div>
</template>

<script>
import axios from 'axios';
export default {
  name: "Word",
  data() {
    return {
      poHtmlCode: "",
    };
  },
  created: function () {
    //由于vue中的axios拦截器给请求加token都得是ajax请求，所以这里必须是axios方式去请求后台打开文件的controller
    axios
      .post("/api/InsertSeal/Word/AddSeal/Word1")
      .then((response) => {
        this.poHtmlCode = response.data;
      })
      .catch(function (err) {
        console.log(err);
      });
  },
  methods: {
    //控件中的一些常用方法都在这里调用，比如保存，打印等等
    //保存
    Save() {
      pageofficectrl.WebSave();
    },

    //加盖印章
    InsertSeal() {
      try {
        pageofficectrl.zoomseal.AddSeal();
      } catch (e) {}
    },

    //验证印章
    VerifySeal() {
      pageofficectrl.zoomseal.VerifySeal();
    },

    //修改密码
    ChangePsw() {
      pageofficectrl.zoomseal.ShowSettingsBox();
    },
    //根据印章名称删除印章（李志签名）
    DeleteByName(){
				let sealsJson=pageofficectrl.zoomseal.SealsAsJson;
				let sealObj = JSON.parse(sealsJson);
				for(var key in sealObj ){
					let sealName=sealObj[key].name;
					if("李志签名"==sealName){
						pageofficectrl.zoomseal.DeleteByName(sealName);
					}
					
				}
				
			  },
        //根据签章人删除印章（李志）
			  DeleteBySigner(){
				let sealsJson=pageofficectrl.zoomseal.SealsAsJson;
				let sealObj = JSON.parse(sealsJson);
				for(var key in sealObj ){
					let sealSigner=sealObj[key].signer;
					if("李志"==sealSigner){
						pageofficectrl.zoomseal.DeleteBySigner("李志");
					}
        }
      },
      OnPageOfficeCtrlInit() {
        // PageOffice的初始化事件回调函数，您可以在这里添加自定义按钮
        pageofficectrl.AddCustomToolButton("保存", "Save", 1);
        pageofficectrl.AddCustomToolButton("加盖印章", "InsertSeal()", 2);
        if(("linux")!=(pageofficectrl.ClientOS)){
          pageofficectrl.AddCustomToolButton("根据印章名称删除印章", "DeleteByName()", 21);
          pageofficectrl.AddCustomToolButton("根据签章人删除印章", "DeleteBySigner", 21);	     				
          pageofficectrl.AddCustomToolButton("验证印章", "VerifySeal()", 5);
          pageofficectrl.AddCustomToolButton("修改密码", "ChangePsw()", 0);
		    }
        
      },
  },
  mounted: function () {
    // 将vue中的方法赋值给window
    window.OnPageOfficeCtrlInit = this.OnPageOfficeCtrlInit;
    window.Save = this.Save;
    window.InsertSeal = this.InsertSeal;
    window.DeleteByName = this.DeleteByName;
		window.DeleteBySigner = this.DeleteBySigner;
    window.VerifySeal = this.VerifySeal;
    window.ChangePsw = this.ChangePsw;
  }
}
</script>

